﻿<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<!-- source http://www.scnoob.com More templates http://www.scnoob.com/moban -->
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>修改收货地址</title>

    <link rel="stylesheet" type="text/css" th:href="@{/assets/css/bootstrap.min.css}">

    <link rel="stylesheet" type="text/css" th:href="@{/assets/fonts/line-icons.css}">

    <link rel="stylesheet" th:href="@{/assets/plugins/morris/morris.css}">

    <link rel="stylesheet" type="text/css" th:href="@{/assets/css/icons.css}">

    <link rel="stylesheet" type="text/css" th:href="@{/assets/css/main.css}">

    <link rel="stylesheet" type="text/css" th:href="@{/assets/css/responsive.css}">
    <link rel="stylesheet" th:href="@{/css/common.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/assets/css/ordergenerateStyles.css}">
    <base th:href="@{/}">
</head>
<body>
<div class="app header-default side-nav-dark">
    <div class="layout">
        <div class="header navbar">
            <div class="header-container">
                <ul class="nav-left">
                    <li>
                        <a href="javascript:history.back(-1);">
                            <i class="lni-chevron-left" style="border: transparent;"></i>
                        </a>
                    </li>
                </ul>
                <p class="text-center d-inline-block phoneNum-title" style="margin-top: 20px">
                    <b>修改收货地址</b>
                </p>
                <ul class="nav-right" style="margin-right: 20px;">
                    <li class="user-profile dropdown dropdown-animated scale-left">

                        <a th:href="@{/front/user/userPath(referId=${referId})}">
                            我的
                        </a>
                        <div style="display: none" th:text="${session.userEntity.id}" id="userId"></div>
                    </li>
                </ul>
            </div>
        </div>
        <div class="footer navbar" style="border-top: 1px solid #f6f6f6;">
            <div class="footer-container">
                <ul class="nav-right" style="margin-right: 20px;">
                    <li class="user-profile dropdown dropdown-animated scale-left">
                        <a >
                            <button type="button" th:onclick="addressSave([[${productId}]],[[${totalNum}]])" class="btn btn-danger btn-rounded" style="padding: 10px 15px;">
                                <span>保存并使用</span>
                            </button>
                        </a>
                    </li>
                </ul>
            </div>
        </div>

        <div class="page-container" style="padding: 40px 0 65px 0!important;background-color: #f1f2f7;">
                <div class="article-clean " style="height: 100%">
                    <div class="container" >
                        <div class="row" >
                            <div class="col-lg-10 col-xl-8 offset-lg-1 offset-xl-2 p-0">
                                <div class="intro" style="padding: 10px">
                                    <div class="card card-body" style="margin-top: 20px;border-radius: 10px;padding: 10px">
                                        <div class="row align-items-center">
                                            <div class="col-md-4 col-lg-3">
                                                <!--主要内容-->
                                                <div class="ordergenerate-center">

                                                    <!--    地址-->
                                                    <div class="ordergenerate-center-address">

                                                        <input class="ordergenerate-center-good-sum-text001" style="display: none" id="id" type="text" th:value="${addressEntity.id}">
                                                        <div>
                                                            <div class="ordergenerate-center-good-sum-text004 text-align-justify d-inline-block" style="width: 26%;">收货人姓名</div>：
                                                            <input class="ordergenerate-center-good-sum-text004 d-inline-block" style="width: 68%" id="username" type="text" th:value="${addressEntity.receiverContact}">
                                                        </div>
                                                        <div class="mt-3">
                                                            <div class="ordergenerate-center-good-sum-text004 text-align-justify d-inline-block" style="width: 26%;">手机号</div>：
                                                            <input class="ordergenerate-center-good-sum-text004 d-inline-block" style="width: 68%" id="phoneNum" type="text" th:value="${addressEntity.receiverMobile}">
                                                        </div>
                                                        <div class="mt-3">
                                                            <div class="ordergenerate-center-good-sum-text004 text-align-justify d-inline-block" style="width: 26%;">收货地址</div>：
                                                            <input class="ordergenerate-center-good-sum-text004 d-inline-block" style="width: 68%" id="address" type="text" th:value="${addressEntity.receiverAddress}">
                                                        </div>
                                                        <div id="tips" style="color: red" class="ordergenerate-center-good-sum-text common-margin"></div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>
<div id="preloader">
    <div class="loader" id="loader-1"></div>
</div>

<script th:src="@{/assets/js/jquery-min.js}"></script>
<script th:src="@{/assets/js/popper.min.js}"></script>
<script th:src="@{/assets/js/bootstrap.min.js}"></script>
<script th:src="@{/assets/js/jquery.app.js}"></script>
<script th:src="@{/assets/js/main.js}"></script>

<script th:src="@{/assets/plugins/morris/morris.min.js}"></script>
<script th:src="@{/assets/plugins/raphael/raphael-min.js}"></script>
<!--<script th:src="@{/assets/js/dashborad1.js}"></script>-->


<script type="text/javascript">
    $(function () {
        $("#tips").hide();
    });

    function addressSave(productId,totalNum) {
        // 电话号码
        var phoneNum = $('#phoneNum').val();
        // 用户名
        var username = $('#username').val();
        // 收货地址
        var address = $('#address').val();
        // 订单提交次数
        var commitNum = $('#commitNum').text();
        if (username==""){
            $("#tips").text("* 收货人不能为空");
            $("#tips").show();
        }else if(!(/^1[345789]\d{9}$/.test(phoneNum))){
            $("#tips").text("* 手机号码格式有误，请重填");
            $("#tips").show();
        }else if (address==""){
            $("#tips").text("* 收货地址不能为空");
            $("#tips").show();
        }else {
            // 判断是否多次提交同一个订单
            if (commitNum==0) {
                commitNum++;
                $('#commitNum').val(commitNum);
                var userId=$("#userId").text();
                console.log(userId);
                $.post("front/addressPhone/addressUpdateAndSave",
                    {
                        "id":$("#id").val(),
                        "userId": userId,
                        "receiverMobile": phoneNum,
                        "receiverContact": username,
                        "receiverAddress": address
                    },
                    function (data) {
                        if (data != "0") {
                            window.open("/front/orderPhone/orderGenerate?productId="+productId+"&totalNum="+totalNum, "_self");
                        } else {
                            $("#tips").text("* 修改地址失败");
                            $("#tips").show();
                        }
                    }
                )
            }else {
                $("#tips").text("* 请勿重复操作");
                $("#tips").show();
            }
        }
    }
</script>
</body>

<!-- source http://www.scnoob.com More templates http://www.scnoob.com/moban -->
</html>